package com.action;

import com.bean.ResponseBean;
import com.service.LogService;
import com.util.StringUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@CrossOrigin
@RestController
@RequestMapping("/log")
public class LogAction {

    @Autowired
    private LogService logService;

    /**
     * 根据时间区间或者用户名查询日志
     * @param name          用户名
     * @param page          页数
     * @param limit         每页条数
     * @param start_time    开始时间
     * @param end_time      结束时间
     * @return
     */
    @RequestMapping("/selectLog")
    public ResponseBean selectLog(String name, int page, int limit, String start_time, String end_time){

//        System.out.println("操作用户："+name+" 页数："+page+" 每页条数："+limit+" 开始时间："+start_time+" 结束时间："+end_time);
        if(page==1){
            page=0;
        }else{
            page=(page*limit)-limit;
        }
        if(StringUtil.isNull(start_time)){
            start_time=null;
        }
        if(StringUtil.isNull(end_time)){
            end_time=null;
        }
        if(StringUtil.isNull(name)){
            name=null;
        }
        return new ResponseBean(0,logService.selectLogCount(name,start_time,end_time),"成功", logService.selectLog(name,page,limit,start_time,end_time));
    }
}
